﻿Imports FinanceiroBLL
Imports FinanceiroDAL
Public Class VisualizaFRM
    Public cod As Integer
    Dim objp As New itensCtasReceberBLL
#Region "Load"
    Private Sub VisualizaFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Try
            Carregagrid()
            somagrid()

        Catch ex As Exception
        End Try
    End Sub
#End Region
#Region "SomaGrid"
    Sub somagrid()
        Try
            Dim valor As Decimal
            For Each col As DataGridViewRow In DGVDados.Rows
                valor = valor + col.Cells("icr_valor").Value
            Next
            TXTTotalGrid.Text = Math.Round(valor, 2, MidpointRounding.AwayFromZero)
            TXTTotalGrid.Text = (valor.ToString.Replace("R$", ""))
            TXTTotalGrid.Text = FormatCurrency(TXTTotalGrid.Text)
            Me.LBNumRegistros.Text = DGVDados.RowCount.ToString 'linhas
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Carregagrid"
    Sub Carregagrid()
        Dim objcp As New ContasReceberBLL
        objcp = New ContasReceberBLL
        DGVDados.DataSource = objcp.localizar(cod, 5)
        DGVDados.Refresh()
    End Sub
#End Region
#Region "Voltar"
    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Close()
        DGVDados.ClearSelection()
        objp = Nothing
    End Sub
#End Region
#Region "Formata Campo"
    Sub formatacampo()
        Dim vlrtotal As Decimal
        If (Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), vlrtotal)) Then
        Else : vlrtotal = "0,00"
        End If
    End Sub
    Private Sub TXTTotalGrid_Leave(sender As System.Object, e As System.EventArgs) Handles TXTTotalGrid.Leave
        formatacampo()
    End Sub

    Private Sub TXTTotalGrid_TextChanged(sender As System.Object, e As System.EventArgs) Handles TXTTotalGrid.TextChanged
        formatacampo()
    End Sub

    Private Sub TXTTotalGrid_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles TXTTotalGrid.MouseUp
        TXTTotalGrid.SelectAll()
    End Sub
#End Region
#Region "Pre paint"
    Private Sub DGVDados_RowPrePaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DGVDados.RowPrePaint
        Me.DGVDados.CurrentRow.Selected = False
        Try
            If DGVDados.Rows.Count > 0 Then
                If (DGVDados.Rows(e.RowIndex).Cells(7).Value = "Aberto") And (DGVDados.Rows(e.RowIndex).Cells(4).Value = Date.Now.ToShortDateString) Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Yellow 'hoje
                End If
                If (DGVDados.Rows(e.RowIndex).Cells(7).Value = "Aberto") And (DGVDados.Rows(e.RowIndex).Cells(4).Value > Date.Now.ToShortDateString) Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 'não vencidas (futuro)
                End If
                If (DGVDados.Rows(e.RowIndex).Cells(7).Value = "Aberto") And (DGVDados.Rows(e.RowIndex).Cells(4).Value < Date.Now.ToShortDateString) Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Salmon 'vencidos
                End If
                If (DGVDados.Rows(e.RowIndex).Cells(7).Value = "Fechado") Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.PaleGreen 'fechados
                End If
                'Else
                '    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 'futuros
            End If
        Catch
        End Try
    End Sub
#End Region
#Region "Keypress"
    Private Sub VisualizaFRM_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub
#End Region
End Class